<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>修改</title>
    <script src="axios.min.js"></script>
    <style>
        .box {
            width: 500px;
            height: 200px;
            position: relative;
        }
        
        input {
            width: 200px;
            height: 25px;
            margin-top: 10px;
            margin-left: 40px;
        }
        
        button {
            width: 50px;
            height: 25px;
            margin-left: 50px;
            margin-top: 10px;
        }
    </style>
</head>

<body>
    <div class="box">
        <input type="text" placeholder="名称">
        <input type="text" placeholder="价格">
        <input type="text" placeholder="描述"><br>
        <button>修改</button>
    </div>
    <script>
        var inps = document.querySelectorAll('input');
        let btn = document.querySelector('button');
        let obj = new URLSearchParams(location.search)
        let pid = obj.get('pid');
        console.log(pid)
        axios({
            method: "get",
            url: `http://localhost:3000/data/${pid}`,
        }).then((data) => {
            let v = data.data;
            console.log(v)
            inps[0].value = v.mz;
            inps[1].value = v.jg;
            inps[2].value = v.js;
            btn.onclick = function() {
                var inps = document.querySelectorAll('input');
                axios({
                    method: "patch",
                    url: `http://localhost:3000/data/${pid}`, //ID
                    data: {
                        mz: inps[0].value,
                        jg: inps[1].value,
                        js: inps[2].value
                        //要修改成什么
                    }
                }).then((data) => {
                    console.log(data)
                    alert('修改成功')
                    location.href = './index.html'
                })
            }

        })
    </script>
</body>

</html>